package cbaServer;

import commonSources.Cliente;
import commonSources.Funcionario;
import commonSources.Painel;
import java.rmi.RemoteException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Hashtable;
import java.util.logging.Level;
import java.util.logging.Logger;

// <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
// #[regen=yes,id=DCE.0AF00B63-EBAA-FC94-C09A-ABC95CC207D1]
// </editor-fold> 
public class BankServer  {

    private DateFormat dateFormat;
   
    private static RMIConnections rmiConn;
    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.6278B75B-5977-2E35-8031-63F6DC2A742A]
    // </editor-fold> 
    private FileHandler handler;
    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.18438F79-2A6E-C268-B94C-70A34DC2F360]
    // </editor-fold> 
    private Hashtable<String, Cliente> listaClientes;
    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.2F845E7C-D2D8-6922-E5B1-9EA5F6C0C312]
    // </editor-fold> 
    private Hashtable<String, Painel> listaPaneis;
    private Hashtable<String, Funcionario> listaFuncionarios;
    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.64C662B0-D911-0353-4F70-5A06F9183557]
    // </editor-fold> 

    public BankServer() throws RemoteException {
        dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        handler = FileHandler.getInstance();
        listaClientes = handler.loadClientes();
        listaPaneis = handler.loadPainels();
        listaFuncionarios = handler.loadFuncionarios();
        rmiConn = new RMIConnections(this);
        rmiConn.criaLigacaoRMI("cba");
        rmiConn.criaLigacaoRMI("remote");
    }

    public static void main(String[] args) {
        try {
            new BankServer();
        } catch (RemoteException ex) {
            Logger.getLogger(BankServer.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    public synchronized Hashtable<String, Cliente> getListaClientes() {
        return this.listaClientes;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,regenBody=yes,id=DCE.4E8C7E12-7AE4-732D-37FB-0A586AA14C07]
    // </editor-fold> 
    public void setListaClientes(Hashtable<String, Cliente> val) {
        this.listaClientes = val;
        getHandler().saveClientes(listaClientes);
    }

    public synchronized void setListaPaneis(Hashtable<String, Painel> val) {
        this.setListaPaneis(val);
        getHandler().savePanels(val);
    }

    public FileHandler getFileHandler() {
        return getHandler();
    }

    public void setFileHandler(FileHandler val) {
        setHandler(val);
    }

    /**
     * @return the handler
     */
    public FileHandler getHandler() {
        return handler;
    }

    /**
     * @param handler the handler to set
     */
    public void setHandler(FileHandler handler) {
        this.handler = handler;
    }

    /**
     * @return the listaFuncionarios
     */
    public Hashtable<String, Funcionario> getListaFuncionarios() {
        return listaFuncionarios;
    }

    /**
     * @param listaFuncionarios the listaFuncionarios to set
     */
    public void setListaFuncionarios(Hashtable<String, Funcionario> listaFuncionarios) {
        this.listaFuncionarios = listaFuncionarios;
    }

    /**
     * @return the listaPaneis
     */
    public Hashtable<String, Painel> getListaPaneis() {
        return listaPaneis;
    }

    /**
     * @return the dateFormat
     */
    public DateFormat getDateFormat() {
        return dateFormat;
    }

    /**
     * @param dateFormat the dateFormat to set
     */
    public void setDateFormat(DateFormat dateFormat) {
        this.dateFormat = dateFormat;
    }
    /**
     * @param listaPaneis the listaPaneis to set
     */
}

